<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.17"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>TMCStepper: src/source/SW_SPI.cpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">TMCStepper
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.17 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('_s_w___s_p_i_8cpp_source.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">SW_SPI.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_s_w___s_p_i_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="_s_w___s_p_i_8h.html">SW_SPI.h</a>&quot;</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160; </div>
<div class="line"><a name="l00003"></a><span class="lineno"><a class="line" href="class_s_w___s_p_i_class.html#abab6ad0e3672f88cb059c7885d0c4388">    3</a></span>&#160;<a class="code" href="class_s_w___s_p_i_class.html#abab6ad0e3672f88cb059c7885d0c4388">SW_SPIClass::SW_SPIClass</a>(uint16_t mosi, uint16_t miso, uint16_t sck) :</div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;  mosi_pin(mosi),</div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;  miso_pin(miso),</div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;  sck_pin(sck)</div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;  {}</div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160; </div>
<div class="line"><a name="l00009"></a><span class="lineno"><a class="line" href="class_s_w___s_p_i_class.html#aa35a68a7e184e42445f391876e58dd68">    9</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="class_s_w___s_p_i_class.html#aa35a68a7e184e42445f391876e58dd68">SW_SPIClass::init</a>() {</div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;  pinMode(mosi_pin, OUTPUT);</div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;  pinMode(sck_pin, OUTPUT);</div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;  pinMode(miso_pin, INPUT_PULLUP);</div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="preprocessor">  #ifdef ARDUINO_ARCH_AVR</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;    mosi_register = portOutputRegister(getPort(mosi_pin));</div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;    miso_register = portInputRegister(getPort(miso_pin));</div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;    sck_register = portOutputRegister(getPort(sck_pin));</div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;    mosi_bm = digitalPinToBitMask(mosi_pin);</div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;    miso_bm = digitalPinToBitMask(miso_pin);</div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;    sck_bm = digitalPinToBitMask(sck_pin);</div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="preprocessor">  #endif</span></div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;  <a class="code" href="_t_m_c__platforms_8h.html#a889f92ec583d898b35cf083e12ef371a">writeSCK_H</a>;</div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;}</div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160; </div>
<div class="line"><a name="l00024"></a><span class="lineno"><a class="line" href="class_s_w___s_p_i_class.html#af260fdc0af3f1312b106483161e559c3">   24</a></span>&#160;uint8_t <a class="code" href="class_s_w___s_p_i_class.html#af260fdc0af3f1312b106483161e559c3">SW_SPIClass::transfer</a>(uint8_t ulVal) {</div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;  uint8_t value = 0;</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;  <a class="code" href="_t_m_c__platforms_8h.html#a595d617b4d8e35526e7c38367baf637c">writeSCK_L</a>;</div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160; </div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;  <span class="keywordflow">for</span> (uint8_t i=7 ; i&gt;=1 ; i--) {</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;    <span class="comment">// Write bit</span></div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;    !!(ulVal &amp; (1 &lt;&lt; i)) ? <a class="code" href="_t_m_c__platforms_8h.html#aae28defc4c391982df05cb414663956e">writeMOSI_H</a> : <a class="code" href="_t_m_c__platforms_8h.html#a00ddb733cb8aae0fc31326e4163cc638">writeMOSI_L</a>;</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;    <span class="comment">// Start clock pulse</span></div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;    <a class="code" href="_t_m_c__platforms_8h.html#a889f92ec583d898b35cf083e12ef371a">writeSCK_H</a>;</div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;    <span class="comment">// Read bit</span></div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;    value |= ( <a class="code" href="_t_m_c__platforms_8h.html#a1b0729059441b53f83a633fbf0ab315f">readMISO</a> ? 1 : 0) &lt;&lt; i;</div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;    <span class="comment">// Stop clock pulse</span></div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;    <a class="code" href="_t_m_c__platforms_8h.html#a595d617b4d8e35526e7c38367baf637c">writeSCK_L</a>;</div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;  }</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160; </div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;  !!(ulVal &amp; (1 &lt;&lt; 0)) ? <a class="code" href="_t_m_c__platforms_8h.html#aae28defc4c391982df05cb414663956e">writeMOSI_H</a> : <a class="code" href="_t_m_c__platforms_8h.html#a00ddb733cb8aae0fc31326e4163cc638">writeMOSI_L</a>;</div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;  <a class="code" href="_t_m_c__platforms_8h.html#a889f92ec583d898b35cf083e12ef371a">writeSCK_H</a>;</div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;  value |= ( <a class="code" href="_t_m_c__platforms_8h.html#a1b0729059441b53f83a633fbf0ab315f">readMISO</a> ? 1 : 0) &lt;&lt; 0;</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160; </div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;  <span class="keywordflow">return</span> value;</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;}</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160; </div>
<div class="line"><a name="l00046"></a><span class="lineno"><a class="line" href="class_s_w___s_p_i_class.html#a1b7600aa1d9571c103718c5d3e376675">   46</a></span>&#160;uint16_t <a class="code" href="class_s_w___s_p_i_class.html#a1b7600aa1d9571c103718c5d3e376675">SW_SPIClass::transfer16</a>(uint16_t data) {</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;  uint16_t returnVal = 0x0000;</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;  returnVal |= <a class="code" href="class_s_w___s_p_i_class.html#af260fdc0af3f1312b106483161e559c3">transfer</a>((data&gt;&gt;8)&amp;0xFF) &lt;&lt; 8;</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;  returnVal |= <a class="code" href="class_s_w___s_p_i_class.html#af260fdc0af3f1312b106483161e559c3">transfer</a>(data&amp;0xFF) &amp; 0xFF;</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;  <span class="keywordflow">return</span> returnVal;</div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;}</div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<div class="ttc" id="aclass_s_w___s_p_i_class_html_a1b7600aa1d9571c103718c5d3e376675"><div class="ttname"><a href="class_s_w___s_p_i_class.html#a1b7600aa1d9571c103718c5d3e376675">SW_SPIClass::transfer16</a></div><div class="ttdeci">uint16_t transfer16(uint16_t data)</div><div class="ttdef"><b>Definition:</b> <a href="_s_w___s_p_i_8cpp_source.html#l00046">SW_SPI.cpp:46</a></div></div>
<div class="ttc" id="a_t_m_c__platforms_8h_html_aae28defc4c391982df05cb414663956e"><div class="ttname"><a href="_t_m_c__platforms_8h.html#aae28defc4c391982df05cb414663956e">writeMOSI_H</a></div><div class="ttdeci">#define writeMOSI_H</div><div class="ttdef"><b>Definition:</b> <a href="_t_m_c__platforms_8h_source.html#l00032">TMC_platforms.h:32</a></div></div>
<div class="ttc" id="a_t_m_c__platforms_8h_html_a1b0729059441b53f83a633fbf0ab315f"><div class="ttname"><a href="_t_m_c__platforms_8h.html#a1b0729059441b53f83a633fbf0ab315f">readMISO</a></div><div class="ttdeci">#define readMISO</div><div class="ttdef"><b>Definition:</b> <a href="_t_m_c__platforms_8h_source.html#l00036">TMC_platforms.h:36</a></div></div>
<div class="ttc" id="aclass_s_w___s_p_i_class_html_af260fdc0af3f1312b106483161e559c3"><div class="ttname"><a href="class_s_w___s_p_i_class.html#af260fdc0af3f1312b106483161e559c3">SW_SPIClass::transfer</a></div><div class="ttdeci">uint8_t transfer(uint8_t ulVal)</div><div class="ttdef"><b>Definition:</b> <a href="_s_w___s_p_i_8cpp_source.html#l00024">SW_SPI.cpp:24</a></div></div>
<div class="ttc" id="aclass_s_w___s_p_i_class_html_aa35a68a7e184e42445f391876e58dd68"><div class="ttname"><a href="class_s_w___s_p_i_class.html#aa35a68a7e184e42445f391876e58dd68">SW_SPIClass::init</a></div><div class="ttdeci">void init()</div><div class="ttdef"><b>Definition:</b> <a href="_s_w___s_p_i_8cpp_source.html#l00009">SW_SPI.cpp:9</a></div></div>
<div class="ttc" id="a_t_m_c__platforms_8h_html_a889f92ec583d898b35cf083e12ef371a"><div class="ttname"><a href="_t_m_c__platforms_8h.html#a889f92ec583d898b35cf083e12ef371a">writeSCK_H</a></div><div class="ttdeci">#define writeSCK_H</div><div class="ttdef"><b>Definition:</b> <a href="_t_m_c__platforms_8h_source.html#l00034">TMC_platforms.h:34</a></div></div>
<div class="ttc" id="a_t_m_c__platforms_8h_html_a00ddb733cb8aae0fc31326e4163cc638"><div class="ttname"><a href="_t_m_c__platforms_8h.html#a00ddb733cb8aae0fc31326e4163cc638">writeMOSI_L</a></div><div class="ttdeci">#define writeMOSI_L</div><div class="ttdef"><b>Definition:</b> <a href="_t_m_c__platforms_8h_source.html#l00033">TMC_platforms.h:33</a></div></div>
<div class="ttc" id="a_s_w___s_p_i_8h_html"><div class="ttname"><a href="_s_w___s_p_i_8h.html">SW_SPI.h</a></div></div>
<div class="ttc" id="a_t_m_c__platforms_8h_html_a595d617b4d8e35526e7c38367baf637c"><div class="ttname"><a href="_t_m_c__platforms_8h.html#a595d617b4d8e35526e7c38367baf637c">writeSCK_L</a></div><div class="ttdeci">#define writeSCK_L</div><div class="ttdef"><b>Definition:</b> <a href="_t_m_c__platforms_8h_source.html#l00035">TMC_platforms.h:35</a></div></div>
<div class="ttc" id="aclass_s_w___s_p_i_class_html_abab6ad0e3672f88cb059c7885d0c4388"><div class="ttname"><a href="class_s_w___s_p_i_class.html#abab6ad0e3672f88cb059c7885d0c4388">SW_SPIClass::SW_SPIClass</a></div><div class="ttdeci">SW_SPIClass(uint16_t sw_mosi_pin, uint16_t sw_miso_pin, uint16_t sw_sck_pin)</div><div class="ttdef"><b>Definition:</b> <a href="_s_w___s_p_i_8cpp_source.html#l00003">SW_SPI.cpp:3</a></div></div>
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="dir_94e7a0fbe7f8eaf7f05ee7b02c647e9f.html">source</a></li><li class="navelem"><a class="el" href="_s_w___s_p_i_8cpp.html">SW_SPI.cpp</a></li>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.17 </li>
  </ul>
</div>
</body>
</html>
